package com.example.e_comm.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {
    @Autowired
    private RedisTemplate<String,Object>redisTemplate;

    public void set(String key, Object value, long time, TimeUnit timeUnit){
        redisTemplate.opsForValue().set(key, value, time, timeUnit);
    }
    public  Object get(String key){
        return redisTemplate.opsForValue().get(key);
    }
    public boolean delete(String key){
        return  Boolean.TRUE.equals(redisTemplate.delete(key));
}
     public boolean hasKay(String key){
        return Boolean.TRUE.equals(redisTemplate.hasKey(key));
}
    public boolean expire(String key,long time,TimeUnit timeUnit){
        return Boolean.TRUE.equals(redisTemplate.expire(key,time,timeUnit));
}


}
